$(document).on('ready', function(e)
{
  $('a[data-delete-noticia]').on('click', function(e)
  {
    e.preventDefault();
    var noticia_id = $(this).data('delete-noticia');
    var $Row = $('#row_noticia_' + noticia_id);

    $.ajax('noticias/actions.php?action=delete',{
      data: {'noticia_id': noticia_id},
      type: 'post',
      dataType: 'json',

      beforeSend: function(jqXHR, Settings)
      {
        $Row.addClass('deleting');
      },
      complete: function(jqXHR, text_status)
      {
        if($Row){
          $Row.removeClass('deleting');
        }
      },
      error: function(jqXHR, text_status, error_thrown)
      {
        alert('Ocurrió un error al procesar la solicitud de borrado.');
      },
      success: function(Result, text_status, jqXHR)
      {
        if(Result.error){
          alert('Error: ' + Result.message);
        } else {
          // Eliminar fila de la noticia
          $Row.fadeOut('slow', function(e)
          {
            $(this).remove();
            delete $Row;
          });
        }
      }
    });
  });
});